package day4;

public class Demo2 {
    public static void main(String[] args) {
        int[] arr = { 2, 5, -1, 9, 23};

        if (arr.length == 0){
            return;
        }

        for (int i : arr){
            System.out.print(i + " ");
        }

        System.out.println();

        QuickSort(arr, 0, arr.length - 1);
    }

    private static void QuickSort(int[] arr, int leftIndex, int rightIndex){
        if (leftIndex > rightIndex){
            return;
        }

        int i = leftIndex;
        int j = rightIndex;

        int p = arr[i];

        while (i < j){
            while (i < j && arr[j] >= p){
                j--;
            }

            arr[i] = arr[j];

            while (i < j && arr[j] <= p){
                i++;
            }
            arr[j] = arr[i];
        }

        arr[i] = p;

    }
}
